package com.personalkeeper;

import java.util.ArrayList;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class PolylineLayer extends Overlay {

    ArrayList<GeoPoint> path = new ArrayList<GeoPoint>();
    int color;
    public PolylineLayer(GeoPoint gp1, GeoPoint gp2, int color) {
        this.color = color;
        path.add(gp1);
        path.add(gp2);
    }
    public PolylineLayer(GeoPoint gp1, int color) {
        this.color = color;
        path.add(gp1);
    }
    public PolylineLayer(int color) {
        this.color = color;
    }
    public void DrawLineTo(GeoPoint gp1) {
        path.add(gp1);
    }
    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        Projection projection = mapView.getProjection();
        Paint paint = new Paint();
        paint.setStrokeWidth(3);
        paint.setColor(this.color);
        paint.setAlpha(120);


        Point p1 = new Point();
        Point p2 = new Point();

        if (path.size() > 0) {
            projection.toPixels(path.get(0), p1);
            for (int i = 1; i < path.size(); i++) {
                projection.toPixels(path.get(i), p2);
                canvas.drawLine(p1.x, p1.y, p2.x, p2.y, paint);
                p1.x = p2.x;
                p1.y = p2.y;
            }
        }
        super.draw(canvas, mapView, shadow);
    }
    public void clear() {
        path.clear();

    }
    public void setColor(int color) {
        this.color = color;
    }
}
